//
// Created by Jisam on 2024/7/28 22:47.
// solve b
#include <bits/stdc++.h>

#define PSI pair<string,int>
#define PII pair<int,int>
#define PDI pair<double,int>
#define PDD pair<double,double>
#define VVI vector<vector<int>>
#define VI vector<int>
#define VS vector<string>

#define PQLI priority_queue<int, vector<int>, less<int>>
#define PQGI priority_queue<int, vector<int>, greater<int>>
using u32 = unsigned;
using i64 = long long;
using u64 = unsigned long long;

using namespace std;


void solve() {
    int n;
    cin >> n;
    vector<int> b(n),a(n);
    iota(a.begin(),a.end(),n);
    for(int i =  0; i < n - 1; i ++)
    {
        cin >> b[i];
    }
    for(int i = 0 ; i < n - 1; i ++)
    {
//        if(cur == (a[i] ^ b[i]) ) {
//            cout << "-1\n";
//            return;
//        }
//         cur = a[i] ^ b[i];
//        cout << (0 ^ b[i]) <<" ";
        while((a[i] & a[i + 1]) != b[i]){
//            cout << (a[i] & a[i + 1]) <<" a[i] & a[i + 1] \n";
            a[i + 1] --;
        }
    }
    for(int i = 0; i < n ; i ++){
        cout << a[i] <<" ";
    }
//    cout << "1";
    cout << "\n";
//    if(judge){
//        cout << -1 <<"\n";
//    }else{
//        cout << 1 <<"\n";
//    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    cin >> T;
    while (T--) solve();
//    cout << "\n"[];
    return 0;
}